<template>
	<view class="route-container">
		<view class="route-header">
			<!-- 作者信息 -->
			<view class="author-wrapper">
				<image :src="userData.avatarUrl" />
				<view class="author-info">
					<view class="author-name">{{ userData.nickname }}</view>
					<view class="author-desc">{{ userData.signature }}</view>
				</view>
			</view>

			<!-- 路线标题 -->
			<view class="route-title"> {{ route.title }} </view>

			<!-- 路线标签 -->
			<view class="route-tag-wrapper">
				<view v-for="item in route.destinationList" :key="item.id" class="tag">#{{ item.destination }}</view>
			</view>
		</view>

		<!-- AI路线基本信息 -->
		<view class="route-baseinfo">
			<view class="route-baseinfo-title">
				<image src="@/static/icon/route2.png" class="icon" />
				AI推荐路线概览
			</view>
			<view class="route-baseinfo-item">
				<image src="@/static/icon/calendar.png" class="icon" />
				行程天数: {{ route.day }}天
			</view>
			<view class="route-baseinfo-item">
				<image src="@/static/icon/walk.png" class="icon" />
				行程人数: {{ route.member }}人
			</view>
			<view class="route-baseinfo-item">
				<image src="@/static/icon/site.png" class="icon" />
				旅行地点: {{ route.destination }}
			</view>
		</view>

		<!-- 旅游路线 -->
		<view class="route-list">
			<view v-for="item in route.route" :key="item.id" class="route-item">
				<view class="arrival-time">{{ item.arrivalTime }}</view>
				<view class="spot">
					<image :src="item.image" class="spot-image" />
					<view class="spot-info">
						<view class="spot-name">{{ item.location }}</view>
						<view class="spot-desc">{{ item.description }}</view>
						<view class="play-mode">
							{{ item.playMode }}
						</view>
						<view class="transportation">
							<image src="@/static/icon/train.png" class="icon" /> {{ item.transportation }}
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- AI智能建议 -->
		<view class="checklist">
			<view class="checklist-title">
				<image src="@/static/icon/light.png" />
				AI智能提醒
			</view>
			<view class="checklist-item"> 手机、充电器 </view>
			<view class="checklist-item"> 身份证 </view>
			<view class="checklist-item"> 适量现金 </view>
		</view>
	</view>
</template>

<script>
import request from '@/api/http.js';

export default {
	data() {
		return {
			routeId: 0,
			route: {},
			userData: {}
		};
	},
	onLoad(option) {
		if (option?.id) {
			this.routeId = option.id;
			this.handleGetRoute(this.routeId);
		} else {
			this.handleGetRoute(20);
		}
	},
	methods: {
		async handleGetRoute(id) {
			const res = await request('/travel/getTravel', { travelId: id });
			this.route = res.data.data;

			await this.handleGetUserData(this.route.userId);
		},
		async handleGetUserData(userId) {
			const res = await request('/users/getUserData', { userId });
			this.userData = res.data;
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f5f5f5;
}

.route-container {
	display: flex;
	flex-direction: column;

	.route-header {
		background-color: #fff;
		width: 100%;
		padding: 20rpx;
		margin-bottom: 20rpx;

		.author-wrapper {
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;

			image {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}

			.author-info {
				.author-name {
					font-size: 32rpx;
					font-weight: bold;
				}

				.author-desc {
					font-size: 28rpx;
					color: #999;
				}
			}
		}

		.route-title {
			font-size: 36rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}

		.route-tag-wrapper {
			display: flex;
			margin-bottom: 20rpx;

			.tag {
				background-color: #eff6ff;
				padding: 10rpx 20rpx;
				border-radius: 30rpx;
				margin-right: 20rpx;
				font-size: 28rpx;
				color: #007aff;

				&:active {
					background-color: #e2edfc;
				}
			}
		}
	}

	.route-baseinfo {
		background-color: #fff;
		margin: 20rpx 40rpx;
		padding: 20rpx 30rpx;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		gap: 20rpx;
		box-shadow: 0px 3px 9px #eee;

		&-title {
			display: flex;
			align-items: center;
			font-size: 30rpx;
			color: #000;
			font-weight: bold;

			.icon {
				width: 40rpx;
				height: 40rpx;
				margin-right: 14rpx;
			}
		}

		&-item {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			color: #666;

			.icon {
				width: 32rpx;
				height: 32rpx;
				margin-right: 20rpx;
			}
		}
	}

	.route-list {
		background-color: #fff;
		padding: 40rpx;

		.route-item {
			display: flex;
			justify-content: space-between;
			margin-bottom: 20rpx;


			.arrival-time {
				font-size: 28rpx;
				color: #666;

			}

			.spot {
				width: calc(100% - 120rpx);
				background-color: #fff;
				border-radius: 25rpx;
				box-shadow: 0px 3px 9px #eee;
				overflow: hidden;

				.spot-image {
					width: 100%;
					height: 400rpx;
					object-fit: cover;
				}

				.spot-info {
					display: flex;
					flex-direction: column;
					padding: 20rpx;
					font-size: 28rpx;
					color: #333;

					.spot-name {
						font-size: 32rpx;
						font-weight: bold;
						color: #000;
					}

					.spot-desc {
						color: #333;
					}

					.transportation {
						display: flex;
						align-items: center;
						margin-top: 20rpx;

						.icon {
							width: 32rpx;
							min-width: 32rpx;
							height: 32rpx;
							margin-right: 20rpx;
						}
					}

					.play-mode {
						margin-top: 20rpx;

						.icon {
							width: 32rpx;
							height: 32rpx;
							margin-right: 20rpx;
						}
					}
				}
			}
		}
	}

	.checklist {
		background-color: #eff6ff;
		margin: 20rpx 40rpx;
		padding: 20rpx 30rpx;
		border-radius: 20rpx;
		box-shadow: 0px 3px 9px #eee;

		.checklist-title {
			display: flex;
			align-items: center;
			font-size: 30rpx;
			font-weight: bold;
			color: #000;
			margin-bottom: 20rpx;

			image {
				width: 40rpx;
				height: 40rpx;
				margin-right: 14rpx;
			}
		}

		.checklist-item {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			color: #666;
			margin-bottom: 20rpx;

			&::before {
				content: '';
				width: 10rpx;
				height: 10rpx;
				background-color: #007aff;
				border-radius: 100%;
				margin-right: 20rpx;
			}
		}
	}
}
</style>
